#! /usr/bin/python

####
# check the job statistics for the jobs defined in the given configuration file 
# -. reads in and parse the configuration file to find "master" address and port;
# -. connects (via socket) to the master requesting statistics of the job progress.  
#
#### 
import os
import socket
import sys
import ConfigParser
import logging

###### parameter parsing #####
if len(sys.argv) < 3:
	print 'usage'
	print '-----'
	print ''
	print 'to_master.py config_file message'
	print ' '
	print ' '
	print 'Inputs:'
	print '-------'
	print 'The configuration file that discribes the jobs and the dispatching setup.'
	print 'For more information please refer to the in-line comments in the example.conf.'
	sys.exit(1)

###### read in configuration file ##### 
config_file = sys.argv[1]
config=ConfigParser.SafeConfigParser()
config.read(config_file)

message = sys.argv[2]

###### get the "master" information and make the connection #####
master_host = config.get('MASTER','host')
master_port = config.getint('MASTER','port') 
master_conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
master_conn.connect((master_host,master_port))
master_conn.sendall(message) # asking for job statistics 

###### clean up and die ####

master_conn.close()
